package com.zhangmengyuan.medical.controller;


import com.zhangmengyuan.medical.entity.Orderinfo;
import com.zhangmengyuan.medical.service.OrderinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("orderinfo")

public class OrderinfoController {
    @Autowired
    private OrderinfoService orderinfoService;
    public String save(Orderinfo orderinfo)
    {this.orderinfoService.save(orderinfo);
    return "redirect:orderiofo/all";
    }
    public String update(Orderinfo orderinfo, @PathVariable("orderinfoId") Integer orderinfoId, Model model){
        orderinfo.setOrderinfoId(orderinfoId);
        this.orderinfoService.save(orderinfo);
       return "redirect:orderiofo/all";
    }
    public String getOrderinfo(Model model){
        List<Orderinfo> orderinfoList=this.orderinfoService.getAll();
        model.addAttribute("orderinfoList",orderinfoList);
        return "showinfo";
    }
    public String getOrderinfoById(Orderinfo orderinfo,@PathVariable("orderinfoId")Integer orderinfoId,Model model){
      orderinfo=this.orderinfoService.getById(orderinfoId);
      model.addAttribute("orderinfo",orderinfo);
      return "showinfo";
    }
    public String  toDetil(Model model){return "showinfo";}
}
